package logic

import (
	"context"
	"errors"
	"rent-ease/models/mysql"

	"rent-ease/rentrpc/internal/svc"
	"rent-ease/rentrpc/rentrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源添加
func (l *HouseAddLogic) HouseAdd(in *rentrpc.HouseAddRequest) (*rentrpc.HouseAddResponse, error) {
	// todo: add your logic here and delete this line

	house := mysql.House{
		Title: in.Title,
		Desc:  in.Desc,
		Price: float64(in.Price),
	}

	err := house.HouseAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}

	return &rentrpc.HouseAddResponse{
		HouseId: int64(house.ID),
	}, nil
}
